package logic

import (
	"context"
	"fmt"
	"user_srv/models/mysql"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type PositionAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPositionAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PositionAddLogic {
	return &PositionAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 职位发布
func (l *PositionAddLogic) PositionAdd(in *user.PositionAddRequest) (*user.PositionAddResponse, error) {
	// todo: add your logic here and delete this line

	position := mysql.Position{
		Name:          in.Name,
		Types:         in.Types,
		Address:       in.Address,
		Price:         float64(in.Price),
		Experience:    in.Experience,
		Qualification: in.Qualification,
	}

	if position.Name != "" && position.Price != 0 && position.Types != "" {
		return nil, fmt.Errorf("内容不能为空")
	}

	mysql.DB.Debug().Create(&position)

	return &user.PositionAddResponse{
		Id: int64(position.ID),
	}, nil
}
